<?php

/*
 * Action - 4+$
 *
 * +1 card 
 * +1 action
 * Reveal the top card of your deck. If it is an Action, play it.
 * 
 * When you buy this, you may overpay for it. For each 1$ you overpaid,
 * look through your discard pile and put a card from it on top of your deck.
 * 
 */

class Herald extends Card implements iAction, iKingdom, iGuilds {

    public function __construct() {
        parent::__construct("Herald", 4);
        $this->undoPlay = false;
        $this->undoBuy = false;
    }

    public function getDescription() {
        return array(
            "+1 card",
            "+1 action",
            "Reveal the top card of your deck. If it is an Action, play it.",
            "When you buy this, you may overpay for it. For each 1$ you overpaid, look through your discard pile and put a card from it on top of your deck."
        );
    }

    public function buy(Game $game) {
        $overpay = $game->getOverpayAmount($this->getValue());

        for ($i = 0; $i < $overpay; $i++) {
            $options = $game->getDiscardDeck();
            $options = getUniqueCards($options);
            if (sizeof($options) > 0) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Choose card from the discard deck to put on top of your deck");
                $card = $output[0];
                $game->moveCardFromPileToPile($card, DiscardPile, DrawPile);
                ScreenDisplay::addScreenMessage($game, true, "return " . nicePrint($card). " on top of your deck", "returns 1 card on top of his deck");
            }
        }
        return true;
    }

    public function play(Game $game, $isRealCard) {
        $drawed_cards = $game->drawCards(1);
        $game->addActions(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action and draw " . nicePrint($drawed_cards), "get +1 action and draws " . sizeof($drawed_cards) . " cards");

        $card = $game->peekCardFromDrawDeck();
        ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($card), "reveals " . ScreenDisplay::$LMSG);
        if ($card instanceof iAction) {
            $cards = $game->removeCardsFromDrawDeck(1);
            $card = $game->moveCardFromPileToPile($cards[0], NOPILE, PlayArea);
            ScreenDisplay::addScreenMessage($game, false, " and play it", " and plays it");
            $game->pushCardToStack($card, REAL_CARD);
        } else {
            ScreenDisplay::addScreenMessage($game, false, ", alas, it is not an action, what a shame.", ", horray! it is not an action, what a loser!");
        }
        $game->cardActionFinished();
        return true;
    }

}

?>